package com.dycong.common.leetcode.yi;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-08-09
 * Time: 13:46
 */
public class TreeNodeHeight {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        //递归求解
        int rootLeft = maxDepth(root.left);
        int rootRight = maxDepth(root.right);
        return Math.max(rootLeft, rootRight) + 1;
    }
}
